<template>
	<view class="newNoticeList">
		<viewData :type="'noData'" :nextPage="nextPage" :isTab="false" :isData='isData' :loading="loadingS"
			@onRefresh="onRefresh" :noDatatext="noDatatext">
			<view class="" style="padding-bottom:90rpx ;">
				<view class="search">
					<input class="search-input" v-model="result" placeholder="请输入公告标题" />
					<view class="btn">
						<text style="color: #FFFFFF;" @click="getNewNotice">搜索</text>
					</view>
				</view>
			</view>
			<!-- <view class="bg-white pl-4 pr-4  pb-2 u-m-t-20" style="padding: 20rpx 44rpx;">
				<u-search :show-action="true" action-text="搜索" @custom="getNewNotice()" v-model="result"></u-search>
			</view> -->


			<view class="noticeWrap" style="padding-top: 20rpx;">
				<!--				 <view class="noticeItem"  v-for="(item,index) in noticeList" :key="index" @click="navTo('/pages/authentication/datails',item)">-->
				<view class="noticeItem p-3  shadow" v-for="(item,index) in noticeList" :key="index"
					style="padding: 15px 15px 10px;" @click="navTo('/pages/authentication/noticeDetails',item)">
					<view class="content">
						<view class="unit" style="display:flex;align-items: center;">
							<image class="logo" v-if="item.org_logo" :src="item.org_logo"></image>
							<image class="logo1" v-else src="../../static/image/logo.png"></image>
							<span style="margin-left: 3px;">{{item.notice_type}}</span>
						</view>

						<span class="notice-failure" v-if="item.state == '已作废'">
							已作废
						</span>
						<span class="notice-failure" v-if="item.state == '已失效'">
							已失效
						</span>

						<span class="notice-typePuTong"
							v-if="item.state != '已作废' && item.state != '已失效' && item.notification_type == 1 ">
							普通
						</span>
						<span class="notice-type"
							v-if="item.state != '已作废' && item.state != '已失效' && item.notification_type == 2">
							紧急
						</span>

					</view>

					<view class="">
						<view class="one">
							<!-- <view class="title">{{item.notice_text}}</view> -->
							<view class="title flex" style="font-size: 32rpx;">
								<span>{{item.notice_name}}</span>
								<view v-show="item.dot && item.state != '已作废'&&item.state != '已失效' "
									style="width: 20rpx;height: 20rpx;border-radius: 7px;background-color: #FF3B30;margin-top:-6rpx ;">
								</view>
							</view>
							<!-- <view class="status">{{item.isread?'已读':'未读' }}</view> -->
							<!-- <view class="status" v-if="item.dot ">
							未读
						</view> -->

						</view>
						<view class="two" v-html="item.text.replace(/<\/?[^>]*>/g, '').slice(0,55)+'...'">
						</view>
						<view class="three">

							<view style="display: flex;">
								<view style="width: 23px;height: 11px;margin-top: 1px;padding-right: 5px;">
									<image style="width: 100%;height: 100%;" src="../../static/image/browse.png" alt="">
									</image>
								</view>
								{{item.seeCount}}
							</view>
							<view style="color:#999999">
								{{item.beginTime.substring(0,4)==9999?'永久有效':item.beginTime.substring(0,10)}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</viewData>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isNotice: true,
				noticeList: [],
				// type: 1,
				nextPage: true, //是否有下一页
				index: 0,
				current: 0,
				status: 'loadmore',
				loadText: {
					loadmore: '轻轻上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				searchData: {},
				pageInfo: {
					page: 1
				},
				pageIndex: 1,
				loading: false, //是否加载下一页
				loadingS: false, //是否显示加载更多
				type: 1,
				result: '',
				noDatatext: "暂无通知",
				isData: false,
			}
		},
		onShow() {
			this.checkLogin();
			this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
			this.getNewNotice();
		},
		mounted() {

		},
		onPullDownRefresh() {
			this.checkLogin();
			this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
			this.getNewNotice();
		},
		methods: {
			// 验证是否登录或实名认证
			checkLogin() {

				let _this = this
				if (uni.getStorageSync('phone')) {
					if (uni.getStorageSync('loginFlag')) {
						if (!uni.getStorageSync('hourseList')) {
							uni.showModal({
								title: '请先进行业主认证',
								showCancel: false,
								confirmText: '确认',
								confirmColor: '#F9A832',
								success: function(res) {
									if (res.confirm) {
										_this.$Router.push({
											path: '/pages/address/address'
										})
									}
								}
							});
							this.$openInvite()
						}
					} else {
						uni.showModal({
							title: '请先实名认证',
							showCancel: false,
							confirmText: '确认',
							confirmColor: '#F9A832',
							success: function(res) {
								if (res.confirm) {
									_this.$Router.push({
										path: '/pages/realName/realName'
									})
								}
							}
						});
					}
				} else {
					uni.showModal({
						title: '请先登录',
						showCancel: false,
						confirmText: '确认',
						confirmColor: '#F9A832',
						success: function(res) {
							if (res.confirm) {
								console.log('a')
								_this.$Router.pushTab({
									path: '/pages/user/user'
								})
							}
						}
					});
				}

			},
			onRefresh() {
				console.log('this.nextPage======', this.nextPage)
				if (this.nextPage) {
					console.log(33)
					this.pageIndex = this.pageIndex + 1;
					this.getNewNotice();
				}
			},
			//newNotice 通知接口
			async getNewNotice() {
				// if (this.pageIndex < 2) {
				uni.showLoading({
					title: '加载中'
				});
				// }
				this.loading = false;
				console.log(uni.getStorageSync('projectItem'))
				let res = await this.$request.api.newNotice({
					user_id: uni.getStorageSync('rawData').userId,
					notice_type: '业主端', //查询类型    助业网，员工端 业主端
					pageIndex: this.pageIndex,
					room_id: this.homelist.roomId,
					result: this.result,
					proId: uni.getStorageSync('projectItem').proId

				}).then(res => {
					uni.hideLoading()
					if (res.data.data.datalist < 10) {
						this.nextPage = false
					}
					if (this.pageIndex == 1) {
						this.noticeList = res.data.data.datalist || [];
					} else {
						this.noticeList = [...this.noticeList, ...res.data.data.datalist];
					}
					// this.noticeList = res.data.data.datalist
					// console.log(this.noticeList)
					this.loading = true;
					if (this.noticeList.length > 0) {
						this.loadingS = true;
					}
					console.log('this.loadingSthis.loadingSthis.loadingS', this.loadingS)
					uni.hideLoading();
					// this.noticeList = res.data.data.datalist || [];
					this.isNotice = res.data.data.readState || true;
				}, err => {
					uni.hideLoading();
					uni.showToast({
						title: err.errorMessage,
						duration: 2000,
						icon: 'none'
					});
					return;
				});
				uni.stopPullDownRefresh()
			},

			navTo(url, item) {
				let items = encodeURIComponent(JSON.stringify(item))
				uni.navigateTo({
					url: url + '?item=' + items
				});
			},
		}

	}
</script>

<style lang="scss">
	.statuss {
		width: 96rpx;
		height: 36rpx;
		background: #e5e5e5;
		border-radius: 10rpx;
		// border: 1px solid #d1d1d1;
		color: white;
		text-align: center;
		line-height: 32rpx;
		font-size: 24rpx;
	}

	.newNoticeList {
		min-height: 100vh;
		background-color: #f4f4f4;

		.noticeWrap {
			padding: 22rpx 22rpx 0;

			.noticeItem {
				position: relative;
				background: #FFFFFF;
				border-radius: 12rpx;
				margin-bottom: 10rpx;

				.content {
					display: flex;
					justify-content: space-between;
				}

				.unit {
					font-size: 24rpx;
				}

				.logo {
					width: 40rpx;
					height: 40rpx;
					vertical-align: middle;
				}

				.logo1 {
					width: 30rpx;
					height: 30rpx
				}
			}

			.notice-type {

				font-size: 28rpx;
				color: rgb(255, 255, 255);
				background: red;
				padding: 10rpx 20rpx;
				text-align: center;
				border-bottom-right-radius: 20rpx;
				border-top-left-radius: 20rpx
			}

			.notice-typePuTong {

				font-size: 28rpx;
				color: rgb(255, 255, 255);
				background: rgb(85, 170, 0);
				padding: 10rpx 20rpx;
				text-align: center;
				border-bottom-right-radius: 20rpx;
				border-top-left-radius: 20rpx
			}

			.notice-failure {
				font-size: 26rpx;
				color: rgb(255, 255, 255);
				background: rgb(153, 153, 153);
				padding: 10rpx 20rpx;
				text-align: center;
				font-size: 28rpx;
				border-bottom-right-radius: 20rpx;
				border-top-left-radius: 20rpx
			}

			.one {
				margin-top: 20rpx;
				display: flex;
				justify-content: space-between;

				.title {
					font-weight: bold;
					font-size: 36rpx;
				}

				.status {
					width: 76rpx;
					height: 36rpx;
					background: rgba(253, 54, 54, 0.1);
					border-radius: 24rpx;
					border: 1px solid #FD3636;
					color: red;
					text-align: center;
					line-height: 32rpx;
					font-size: 24rpx;
				}


			}

			.two {
				font-size: 24rpx;
				// font-weight: bold;
				margin-top: 14rpx;
			}

			.three {
				display: flex;
				justify-content: space-between;
				margin-top: 24rpx;
				font-size: 24rpx;
			}
		}



		.Notice {
			width: 100%;
			min-height: 100rpx;
			margin-top: 20rpx;
			background-color: #FFFFFF;

			.cut-off {
				min-height: 110rpx;
				padding: 50rpx 27px 0;

				.cut-offL {
					width: 50%;
					float: left;
					font-size: 42rpx;
					line-height: 50rpx;
					font-weight: 700;
				}

				.cut-offR {

					width: 50%;
					float: right;
					font-size: 30rpx;
					text-align: center;
					line-height: 50rpx;

					.Effective {
						width: 31%;
						color: #fff;
						background-color: #46D345;
						border-radius: 5px;
						margin-right: 15px;
						float: right;
						line-height: 21px;
						font-size: 10px;
					}

					.not {
						width: 25%;
						line-height: 19px;
						border: 1px #FD3636 solid;
						color: #FD3636;
						border-radius: 12px;
						margin-right: 9px;
						float: right;
						font-size: 10px;
						background-color: rgba(253, 54, 54, 0.1);
					}

					.nots {
						width: 30%;
						border: 2rpx #DDDDDD solid;
						color: #DDDDDD;
						border-radius: 25rpx;
						margin-right: 10rpx;
						float: right;
					}

					.not_item {
						width: 30%;
						border: 2rpx #999999 solid;
						color: #999999;
						border-radius: 25rpx;
						margin-right: 10rpx;
						float: right;
					}
				}
			}

			.cut-offTxt {
				font-size: 32rpx;
				line-height: 80rpx;
				color: #666666;
				padding: 10rpx 25px;
			}

			.urgent {
				height: 110rpx;
				font-size: 30rpx;
				padding: 10rpx 25px;
				color: #999999;

				.urgent_jin {
					float: left;
					padding: 0 20rpx;
				}

				.browse {
					float: left;
					padding: 0 20rpx;
				}

				.time {
					float: right;
					padding: 0 20rpx;
				}

				.list {
					color: #FD3636;
					float: left;
				}
			}
		}
	}

	.search {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 28rpx;
		color: #3d7fff;
		height: 100rpx;
		border-bottom: 1rpx solid #eeeeee;
		width: 100%;
		padding-left: 30px;
		padding-right: 30px;
		// margin: -14px auto;
		position: fixed;
		top: 0rpx;
		z-index: 20;
		background: #FFFFFF;
		// margin-top: -59px;

		.search-clear {
			width: 36rpx;
			height: 36rpx;
			position: absolute;
			left: 271px;
			top: 50%;
			transform: translateY(-50%);
		}

		.search-input {
			width: 312px;
			height: 66rpx;
			background: #f0f2f5;
			border-radius: 33rpx;
			line-height: 66rpx;
			font-size: 28rpx;
			padding: 0 33rpx;
			color: #333333;
			box-sizing: border-box;
		}

		.btn {
			width: 21%;
			line-height: 29px;
			border-radius: 28rpx;
			text-align: center;
			margin-left: -43px;
			background: linear-gradient(180deg, #76d904 0%, #417505 100%);
		}
	}
</style>